/*
 * EZCP_Sim_Common.h
 *
 *  Created on: Mar 27, 2011
 *      Author: Group 8
 */

#ifndef EZCP_SIM_COMMON_H_
#define EZCP_SIM_COMMON_H_

//Header files
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
#include <errno.h>
#include <err.h>
#include <sys/dispatch.h>
#include <string.h>
#include <stdarg.h>


#include "EZCP_Sim_Comms.h"

//Debug Levels
#define EZ_E 	1
#define EZ_W 	2
#define EZ_I 	3
#define EZ_D 	4

#undef DEBUG

#ifdef DEBUG
#define DEBUG_MODE		//Enable output messages
#else
#undef DEBUG_MODE		//Disable output messages
#endif


#ifdef DEBUG_MODE
#define DEBUG_PRINT(dLvl, fmt, args...) MSG_PRINT(dLvl, fmt , ## args)
//#define DEBUG_PRINT(...) MSG_PRINT(__VA_ARGS__)	//Variadic Macro
#else
#define DEBUG_PRINT(fmt, args...)
#endif

#define DBG
//#undef DBG

#ifdef DBG
#define print(format, args...) printf (format, ## args)
#else
#define print(format, args...)
#endif

#define		SIMDATA_FILE_NAME	"./Simdata.dat"

typedef char 			u8;
typedef unsigned int 	u32;
typedef signed int 		s32;
typedef float 			f32;
typedef double 			f64;

typedef struct stMsgBuffer {
	int		MsgID;
	int		Length;
	msg_data_buf_t Data;

}MsgBuffer;

void ConfigureDebugLevel (int level);
void MSG_PRINT( int DebugLevel, const char* format, ... );

//Function Declarations
void *pf_CommsHandler();
void *pf_GantryHandler();
void *pf_EmergencyHandler();

void *pf_Sender();
void *pf_Receiver();

void EZCP_Simu_CreateChannel();
void EZCP_Simu_RecvOutgoingMsg();

void EZCP_Simu_ConnectToChannel( s32 *si_server_coid );
void EZCP_Simu_ReadIncomingMsg (s32 si_server_coid);
void EZCP_Simu_SendIncomingMsg (s32 si_server_coid, u8 ui_msgid, msg_data_buf_t buf_data);


#endif /* EZCP_SIM_COMMON_H_ */
